
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>订单管理</title>
    <style>
        .order-table { width: 100%; border-collapse: collapse; margin: 20px 0; }
        .order-table th, .order-table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: center;
        }
        .order-table th { background-color: #f2f2f2; }
        .action-form { display: inline-block; margin: 0 5px; }
        .status-update { color: blue; cursor: pointer; }
    </style>
    <script>
        function confirmDelete(orderId) {
            return confirm("确定要删除订单 #" + orderId + " 吗？");
        }
    </script>
</head>
<body>
<h1 style="text-align:center;">我的订单</h1>
<c:if test="${not empty param.status}">
    <div style="color:green; text-align:center;">
        操作成功：${param.status}
    </div>
</c:if>

<table class="order-table">
    <tr>
        <th>订单编号</th>
        <th>菜品名称</th>
        <th>单价</th>
        <th>数量</th>
        <th>总价</th>
        <th>下单时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${orders}" var="order">
        <tr>
            <td>${order.id}</td>
            <td>${order.dishName}</td>
            <td>￥<fmt:formatNumber value="${order.price}" pattern="#.00"/></td>
            <td>
                <form action="OrderServlet" method="post" class="action-form">
                    <input type="hidden" name="action" value="update">
                    <input type="hidden" name="orderId" value="${order.id}">
                    <select name="quantity" onchange="this.form.submit()">
                        <c:forEach begin="1" end="10" var="qty">
                            <option value="${qty}" ${qty == order.quantity ? 'selected' : ''}>${qty}</option>
                        </c:forEach>
                    </select>
                </form>
            </td>
            <td>￥<fmt:formatNumber value="${order.price * order.quantity}" pattern="#.00"/></td>
            <td><fmt:formatDate value="${order.orderTime}" pattern="yyyy-MM-dd HH:mm"/></td>
            <td>${order.status}</td>
            <td>
                <form action="OrderServlet" method="post" class="action-form"
                      onsubmit="return confirmDelete(${order.id})">
                    <input type="hidden" name="action" value="delete">
                    <input type="hidden" name="orderId" value="${order.id}">
                    <button type="submit">删除</button>
                </form>
            </td>
        </tr>
    </c:forEach>
</table>

<div style="text-align: center; margin-top: 20px;">
    <a href="WelcomeServlet">返回菜单</a>
</div>
</body>

<body>
<h1 style="text-align:center;">我的订单</h1>
<!-- 添加退出按钮 -->
<div style="text-align: center; margin: 10px;">
    <a href="LogoutServlet" style="color: red; text-decoration: none;">退出登录</a>
</div>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- 其余代码保持不变 --%>

</html>

